<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			var flag=false;
			function fun(){
				var img=document.getElementById("img");
				var text=document.getElementById("text");
				if(flag==false){
					img.setAttribute("src","img/on.png");
					text.innerText="灯开了";
					text.setAttribute("style","color:red;")
					flag=true;
				}
				else{
					img.setAttribute("src","img/off.png");
					text.innerText="灯关了";
					text.setAttribute("style","color:black;")
					flag=false;
				}
			}
			
		</script>
	</head>
	<body>
		<div onclick="fun()">
			<img src="img/off.png" width="200px" id="img">
			<h1 id="text">点击开关灯</h1>
			
		</div>
	</body>
</html>
